package com.seeyon.apps.reimburseplugin.rest;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.seeyon.client.CTPRestClient;
import com.seeyon.client.CTPServiceClientManager;
import com.seeyon.ctp.util.Strings;

public class ClientResource  {

private static ClientResource clientresource = null;
private String userName  = getProperties().getProperty("restname").trim();/**REST账号**/
private String password  = getProperties().getProperty("restpwd").trim();/**REST密码**/
private String restUrl   = getProperties().getProperty("ip").trim();/**REST接口访问地址**/
private String binduser  = getProperties().getProperty("restbinduser").trim();/**binding OA user**/

public static ClientResource getInstance(){
if(clientresource == null){
 clientresource = new ClientResource();
 }
 return clientresource;
}

public Properties getProperties() {
 Properties prop = new Properties();
 InputStream in = getClass().getResourceAsStream("/com/seeyon/apps/reimburseplugin/rest/seeyon.properties");
 try {
  prop.load(in);
 } catch (IOException e) {
  e.printStackTrace();
 }
 return prop;
}

public CTPRestClient resouresClent(String loginName){
	CTPServiceClientManager clientManager = CTPServiceClientManager.getInstance(restUrl);
	CTPRestClient client = clientManager.getRestClient();
	client.authenticate(userName, password);
	if(Strings.isNotEmpty(loginName)) {
		client.bindUser(loginName);
	}
	return client;
}
}